package com.dq.domain.sys.macro;

import com.dq.vo.baseVo.VO;
import com.dq.domain.base.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.ManyToOne;
import java.util.ArrayList;
import java.util.List;


/**
 * 通用字典表实体
 *
 * @author gewenzhen
 */
@Data
@Entity
@ApiModel(value = "通用字典库")
public class SysMacro extends BaseEntity implements VO.ToVO {
    //父级id
    @ManyToOne
    @ApiModelProperty(value = "父级", hidden = true)
    protected SysMacro parent;
    //名称
    @ApiModelProperty(value = "名称")
    protected String name;
    //值
    @ApiModelProperty(value = "值")
    protected String value;
    @Enumerated(EnumType.ORDINAL)
    @ApiModelProperty("状态")
    protected Status status;
    @ApiModelProperty("类型")
    @Enumerated(EnumType.ORDINAL)
    protected Type type;
    //排序
    @ApiModelProperty(value = "排序")
    protected Long orderNum;
    //描述
    @ApiModelProperty("描述")
    protected String simpleDesc;

    @Data
    @ApiModel(value = "单位视图")
    public static class Vo implements VO {
        @ApiModelProperty("id")
        private Long id;
        @ApiModelProperty("名称")
        private String name;
        @ApiModelProperty("排序")
        private Long orderNum;
        @ApiModelProperty("值")
        private String value;
        @ApiModelProperty("描述")
        private String simpleDesc;
        @ApiModelProperty("父级id")
        private Long parentId;
        @ApiModelProperty("父级名称")
        private String parentName;
        @ApiModelProperty("状态")
        private Status status;
        @ApiModelProperty("类型")
        private Type type;
        @ApiModelProperty("子类别")
        private List<Vo> childs = new ArrayList<>();
    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();
        vo.id = this.id;
        vo.name = this.name;
        vo.value = this.value;
        vo.orderNum = this.orderNum;
        vo.parentId = this.parent == null ? null : this.parent.id;
        vo.parentName = this.parent == null ? "" : this.parent.name;
        vo.type = this.type;
        vo.status = this.status;
        vo.simpleDesc = this.simpleDesc;
        return vo;
    }

    public enum Status {
        hide("隐藏"), show("显示"),;

        Status(String name) {
            this.name = name;
        }

        public String name;
    }

    public enum Type {
        list("目录"), param("参数配置");

        Type(String name) {
            this.name = name;
        }

        public String name;
    }
}
